#include <iostream>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;

void output(vector<int>& arr) {
	int n = arr.size(), len = 0;
	for (int i = 0; i < n; i++) len += printf("%3d", i);
	cout << "\n";
	
	for (int i = 0; i < len; i++)printf("-");
	cout << "\n";
	
	for (int i = 0; i < n; i++) len += printf("%3d", arr[i]);
	cout << "\n";
}

int main(){
	int n;
	cin >> n;
	vector<int> arr;
	arr.push_back(-1); //假如极小值为-1
	stack<int> s;
	for (int i = 0, a; i < n; i++) {
		cin >> a;
		arr.push_back(a);
	}
	arr.push_back(-1); //假如极小值为-1
	vector<int> l(arr.size() + 1), r(arr.size() + 1);
	output(arr);

	//右侧
	for (int i = 0;  i < arr.size(); i++) {
		while (!s.empty() && arr[s.top()] > arr[i]) {
			r[s.top()] = i;
			s.pop();
		}
		s.push(i);
	}

	//左侧 (倒着扫描)
	while (!s.empty()) s.pop();
	for (int i = arr.size() - 1; i >= 0; i--) {
		while (!s.empty() && arr[s.top()] > arr[i]) {
			l[s.top()] = i;
			s.pop();
		}
		s.push(i);
	}

	for (int i = 1; i <= n; i++) {
		printf("arr[%d] = %d, right : arr[%d] = %d, left : arr[%d] = %d\n",
			i, arr[i],
			r[i], arr[r[i]],
			l[i], arr[l[i]]);
	}
	return 0;
}

//测试数据
// 10 
// 7 8 5 6 2 3 4 1 10 9